<template>
	<view>
		<Header title="发送平台建单" />
		<view class="" style="height: 100rpx;"></view>
		<view class="shurbox">
			<view class="shurbox_title">基本信息</view>
			<view class="input_box" style="margin-top: 60rpx;">
				<view class="input_box_view">
					<view class="input_box_flex">
						<view class="input_box_wen">*</view>
						<view class="input_box_title">运营商：</view>
					</view>
					<view class="change_box" @click="tosex(0)">
						<input :placeholder="formData.operator" disabled="!ismodify" style="width: 100%;"></input>
						<u-icon name="arrow-right"></u-icon>
					</view>

				</view>
				<view class="linex"></view>
			</view>
			<view class="input_box">
				<view class="input_box_view">
					<view class="input_box_flex">
						<view class="input_box_wen">*</view>
						<view class="input_box_title">承运车队：</view>
					</view>
					<view class="change_box" @click="tosex(1)">
						<input :placeholder="formData.fleetName" disabled="!ismodify" style="width: 100%;"></input>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="linex"></view>
			</view>
			<view class="input_box">
				<view class="input_box_view">
					<view class="input_box_flex">
						<view class="input_box_wen">*</view>
						<view class="input_box_title">司机：</view>
					</view>
					<view class="change_box" @click="tosex(2)">
						<input :placeholder="formData.driverName" disabled="!ismodify" style="width: 100%;"></input>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
			</view>
		</view>

		<view class="gbi_box1">
			<view class="gbi_box_fontw">运单图片</view>
			<view class="gbi_box1_image" style="display: flex;align-items: center;">
				
				<view class="felx_box">
					<view class="gbi_box1_image_xia" @click="uploadImg">
						<view>
							<image src="@/static/order/xiangji.png" mode="aspectFill" style="width: 51rpx;height: 46rpx;">
							</image>
							<view style="font-size: 22rpx;color: #999999;">照片/拍照</view>
						</view>
					</view>
					<view style="margin-left: 20rpx;position: relative;" v-for="(item,i) in formData.list">
						<view style="width: 100%;height: 100%;">
							<image :src="item.url" mode="aspectFill"
								style="width: 136rpx;height: 136rpx;border-radius: 10rpx;"></image>
							<image @click.stop.passive="sandia(i)" src="@/static/tabBar/sanchu.png" mode="aspectFill"
								class="sanimage"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="tijiao" @click="sumlit">提交</view>
		<u-picker :show="showpicker" :columns="columns" @close='showpicker=false' @confirm='confirm'
			@cancel='showpicker=false'></u-picker>
		<u-picker :show="showpicker1" :columns="columns1" @close='showpicker1=false' @confirm='confirm1'
			@cancel='showpicker1=false'></u-picker>
		<u-picker :show="showpicker2" :columns="columns2" @close='showpicker2=false' @confirm='confirm2'
			@cancel='showpicker2=false'></u-picker>
	</view>
</template>

<script>
	import Header from '@/components/header/header.vue'
	import utils from '@/utils/file.js'
	export default {
		components: {
			Header
		},
		data() {
			return {
				sex: '请选择',
				formData: {
					list: [],
					operator: '请选择',
					supplierId: '',
					fleetName: '请选择',
					fleetId: '',
					driverName: '请选择',
					driverId: '',
					platform: 1
				},
				show: false,
				showpicker: false,
				showpicker1: false,
				showpicker2: false,
				columns: [
					[]
				],
				columns1: [
					[]
				],
				columns2: [
					[]
				],
				cont: 0,
				supplierId: '',
				appointSupplierId: '',
				mood: [],
				mood1: [],
				mood2: [],
				result:''
			}
		},
		onLoad() {
			this.cread()
		},
		methods: {
			async sumlit() {
				if(this.result.cert_status!=2){
					uni.showToast({
						title:"司机未认证",
						icon:"none"
					})
					return false
				}
				if (!this.formData.supplierId || !this.formData.supplierId || !this.formData.driverId) {
					uni.showToast({
						title: '请提供完整的数据！',
						icon: 'none'
					})
					return false
				}
				if (this.formData.list.length ==0) {
					uni.showToast({
						title: '请提供相关照片！',
						icon: 'none'
					})
					return false
				}
				let res = await this.$http.order.addCreateOder(this.formData)
				//console.log(res)
				if (res.data.code == 200) {
					uni.showToast({
						title: '创建成功',
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}
			},
			async cread() {
			this.$http.order.queryDriverStateDetail({}).then((res) => {
					if(res.data.code==200){
						this.result = res.data.data;
					}
				});
			},
			confirm(e) {
					this.formData.operator = this.mood[e.indexs[0]].supplierName
					this.formData.supplierId = this.mood[e.indexs[0]].supplierId
					this.formData.fleetName = '请选择'
					this.formData.fleetId = ''
					this.formData.driverName = '请选择'
					this.formData.driverId = ''
			
				this.showpicker = false
			},
			confirm1(e) {
				this.formData.fleetName = this.mood1[e.indexs[0]].fleetName
				this.formData.fleetId = this.mood1[e.indexs[0]].fleetId
				this.formData.driverName = '请选择'
				this.formData.driverId = ''
				this.showpicker1 = false
			},
			confirm2(e) {
				this.formData.driverName = this.mood2[e.indexs[0]].driverName
				this.formData.driverId = this.mood2[e.indexs[0]].driverId
				this.showpicker2 = false
			},
			tosex(e) {
				this.cont = e
				if (e == 0) {
					this.shppier()
				} else if (e == 1) {
					this.fleet()
				} else {
					this.diver()
				}
			},
			async shppier() {
				let res = await this.$http.order.listPullDown()
				let data = res.data.data.records
				this.mood = data
				this.columns = [
					[]
				]
				data.forEach(item => {
					this.columns[0].push(item.supplierName)
				})
				this.showpicker = true
				// this.columns[0] = res.data.
			},
			async fleet() {
				if (!this.formData.supplierId) {
					uni.showToast({
						title: '请先选择运营商',
						icon: 'none'
					})
					return false
				}
				let res = await this.$http.order.fleetlistPullDown({
					supplierId: this.formData.supplierId
				})
				let data = res.data.data.records
				this.mood1 = data
				this.columns1 = [
					[]
				]
				data.forEach(item => {
					this.columns1[0].push(item.fleetName)
				})
				this.showpicker1 = true
			},
			async diver() {
				if (!this.formData.fleetId) {
					uni.showToast({
						title: '请先选择承运车队',
						icon: 'none'
					})
					return false
				}
				let res = await this.$http.order.queryDriverAndVehicle({
					appointSupplierId: this.formData.fleetId
				})
				let data = res.data.data
				this.mood2 = data
				this.columns2 = [
					[]
				]
				data.forEach(item => {
					this.columns2[0].push(item.driverName)
				})
				this.showpicker2 = true
			},

			sandia(e) {
				this.formData.list.forEach((item, i) => {
					if (e == i) {
						this.formData.list.splice(i, 1)
					}
				})
			},
			uploadImg(index) {
				let that = this
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					success: (res) => {
						const tempFilePaths = res.tempFilePaths //图片临时数组
						let obj = {
							file: tempFilePaths[0]
						}
						utils.AuploadFile(obj).then(res1 => {
							if (res1.code == 200) {
								that.formData.list.push({
									url: res1.data.url,
								})
							}
						})

					}
				})
			},
		}
	}
</script>

<style>
	.tijiao {
		width: 650rpx;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #00A0E9;
		border-radius: 10rpx;
		color: #fff;
		text-align: center;
		position: fixed;
		bottom: 2%;
		margin-left: 7%;
	}

	.linex {
		width: 630rpx;
		border-bottom: 1rpx solid #EEEEEE;
		margin-top: 40rpx;
		margin-bottom: 40rpx;
	}

	.input_box {
		margin-left: 60rpx;
		margin-right: 60rpx;
	}

	.shurbox {
		background-color: #fff;
		padding-top: 60rpx;
		padding-bottom: 60rpx;
	}

	.change_box {
		display: flex;
		align-items: center;
		width: 70%;
	}

	.shurbox_title {
		font-weight: 600;
		margin-left: 60rpx;
	}

	.input_box_flex {
		display: flex;
		width: 30%;
	}

	.input_box_wen {
		margin-right: 10rpx;
		color: #F8474F;
	}

	.input_box_title {
		color: #444444;
		font-size: 26rpx;
	}

	.input_box_view {
		font-size: 28rpx;
		display: flex;
		align-items: center;
	}

	.input_box input {
		text-align: right;
		font-size: 26rpx;
		width: 70%;
		color: #999999;
	}

	.textarea_box {
		padding: 20rpx;
		background-color: #F7F9FB;
		width: 600rpx;
		height: 240rpx;
		margin-left: 40rpx;
		margin-top: 32rpx;
		border-radius: 10rpx;

		


	}
textarea {
			font-size: 28rpx;
			line-height: 45rpx;
			width: 590rpx;
			height: 240rpx;
		}
	.saxasd {
		width: 710rpx;
		height: 90rpx;
		text-align: center;
		line-height: 90rpx;
		background-color: #00A0E9;
		border-radius: 10rpx;
		color: #fff;
		margin-left: 0rpx;
		margin-top: 40rpx;
		margin-left: 20rpx;

	}

	.sanimage {
		width: 30rpx;
		height: 30rpx;
		position: absolute;
		top: -5%;
		right: -5%;
		z-index: 99999;
	}

	.felx_box {
		display: flex;
		margin-top: 30rpx;
		flex-wrap: wrap;
		margin-left: 60rpx;
		
	}

	.gbi_box1_image_xia {
		width: 136rpx;
		height: 136rpx;
		background-color: #F7F9FB;
		border-radius: 10rpx;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 20rpx;
	}

	.fuwenb {
		width: 610rpx;
		height: 240rpx;
		background-color: #F7F9FB;
		border-radius: 10rpx;
		margin-left: 40rpx;
		font-size: 24rpx;
		padding-top: 23rpx;
		padding-left: 25rpx;
		margin-top: 32rpx;
	}

	.gbi_box_item {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		justify-content: space-between;
		padding-left: 38rpx;
		padding-right: 38rpx;
	}

	.gbi_box_item_sun {
		width: 188rpx;
		height: 72rpx;
		border: 1rpx solid #00A0E9;
		border-radius: 8rpx;
		margin-top: 23rpx;
		text-align: center;
		line-height: 72rpx;
		background-color: #F1F9FF;
		color: #00A0E9;
		font-size: 26rpx;
		font-weight: 100;
	}

	.gbi_box_item_sun1 {
		width: 188rpx;
		height: 72rpx;
		border: 1rpx solid #E7E7E8;
		border-radius: 8rpx;
		margin-top: 23rpx;
		text-align: center;
		line-height: 72rpx;


		font-size: 26rpx;
		font-weight: 100;
	}

	.gbi_box {
		width: 710rpx;
		height: 338rpx;
		background-color: #fff;
		margin-left: 20rpx;
		border-radius: 10rpx;
	}

	.gbi_box1 {
		background-color: #fff;
		border-radius: 10rpx;
		margin-top: 23rpx;
		padding-bottom: 50rpx;
	}

	.gbi_box_fontw {
		font-weight: 600;
		font-size: 32rpx;
		padding-top: 50rpx;
		padding-left: 60rpx;
		padding-right: 38rpx;
	}

	.num {
		text-align: right;
		color: gray;
		margin-top: -100rpx;
		font-size: 24rpx;
		display: flex;
		justify-content: flex-end;
		width: 100%;
		color: #999999;
	}
</style>